﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using System.Data;
using System.Text;

namespace Web.frontpage
{
    public partial class index1 : System.Web.UI.Page
    {
        BLL.NewsContent news = new BLL.NewsContent();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Rp_newBind();
                Rp_ProvinceConBind();
                Rp_ConItemBind();
                Rp_NoticeBind();
                Pic_Bind();
            }
        }

       /* protected void login_onclick()
        {
            if (userclass.SelectedValue == "1")
                Response.Redirect("SignUp/login.aspx");
        }*/
        protected void login_onclick()
        {
            Response.Redirect("SignUp/login.aspx");
        }
        /// <summary>
        ///通知通告绑定
        /// </summary>
        protected void Rp_newBind()
        {
            Rp_new.DataSource = news.GetRows(9, "NewsClassId='15' and NewsIsShow ='true'", "NewspubTime desc ");
            Rp_new.DataBind();
        }
        /// <summary>
        /// 省级竞赛绑定
        /// </summary>
        protected void Rp_ProvinceConBind()
        {
            BLL.ContestService contestService =new BLL.ContestService();
            Rp_ProvinceCon.DataSource = contestService.getOuterContests();
            Rp_ProvinceCon.DataBind();
        }
        /// <summary>
        /// 最新动态
        /// </summary>
        protected void Rp_ConItemBind()
        {
            BLL.ContestService contestService = new BLL.ContestService();
            Rp_ConItem.DataSource = contestService.GetProceduresByTime(9,DateTime.Parse("1900/01/01"));
            Rp_ConItem.DataBind();
        }
        /// <summary>
        /// 绑定校内竞赛通告
        /// </summary>
        protected void Rp_NoticeBind()
        {
            BLL.ContestService contestService = new BLL.ContestService();
            Rp_Notice.DataSource = contestService.GetAllV_Contest(10, "COM_TYPE=0", "CON_PUBTIME desc");
            Rp_Notice.DataBind();
        }
        /// <summary>
        /// 图片绑定
        /// </summary>
        protected void Pic_Bind()
        {
            BLL.PhotoService photoservice = new BLL.PhotoService();
            rp_Pic.DataSource = photoservice.GetRoundPhoto();
            rp_Pic.DataBind();
        }
        /// <summary>
        /// 登录事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void login(object sender, EventArgs e)
        {
            string usm = username.Value;
            string pwd = password.Value;
            if (!string.IsNullOrEmpty(usm) || !string.IsNullOrEmpty(pwd))
            {
               // if (userclass.SelectedValue == "1") //即登录为学生
                //{
                    BLL.StudentService students = new BLL.StudentService();
                    BoStudents model = new BoStudents();
                    model.STU_USERNAME = usm;
                    model.STU_PASSWORD = pwd;
                    BoStudents resultModel = students.CheckStudent(model);
                    if (resultModel != null)
                    {
                        Session["studentId"] = resultModel.STU_ID;
                        Session["studentName"] = resultModel.STU_NAME;
                        Response.Redirect("SignUp/SUIndex.aspx");
                    }
                    else
                    {
                        Response.Write("<script>alert(\"用户名或者密码错误\")</script>");
                    }
                }
               // else if (userclass.SelectedValue == "2" || userclass.SelectedValue == "3")//即管理员或者老师
               // {
                 //   Response.Write("<script>alert(\"暂未开放\")</script>");
               // }
           // }
           else
            {
               Response.Write("<script>alert('不允许有空项')</script>");
                return;
            }
        }

    }
}